//
//  XMHomeListTableViewCell.m
//  XunMi
//
//  Created by MacBook on 2024/2/19.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMHomeListTableViewCell.h"

@interface XMHomeListTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *userHeadImgV;
@property (weak, nonatomic) IBOutlet UILabel *userNameLa;
@property (weak, nonatomic) IBOutlet UILabel *userDescLa;
@property (weak, nonatomic) IBOutlet UIButton *userAgeSexBtn;

@property (weak, nonatomic) IBOutlet UIButton *userVipBtn;
@property (weak, nonatomic) IBOutlet UIButton *chatButton;

@property (weak, nonatomic) IBOutlet UIView *onlineView;
@property (weak, nonatomic) IBOutlet UIButton *voiceBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *vipLeadSpace;

@end

@implementation XMHomeListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    kCornerRadius(_onlineView, 4, 0, UIColor.clearColor);
    [_voiceBtn setImagePosition:(XMImagePositionLeft) spacing:4];
}

- (void)setModel:(XMUserModel *)model {
    _model = model;
    [_userHeadImgV sd_setImageWithURL:kStringToUrl(model.avatar.file_url) placeholderImage:model.isMan ? kManHeadImg : kWomanHeadImg];
    self.userNameLa.text = model.showName;
    self.userNameLa.textColor = model.showColor;
    self.userDescLa.text = model.describe;
    [self.userAgeSexBtn setTitle:model.age forState:UIControlStateNormal];
    self.userVipBtn.hidden = [XMUtil isBlankString:model.member_time];
    [self.userAgeSexBtn setImage:kGetImage(model.isMan ? @"xm_man_icon" : @"xm_wman_icon") forState:UIControlStateNormal];
    [self.userAgeSexBtn setBackgroundImage:kGetImage(model.isMan ? @"home_msex_bg" : @"home_wsex_bg") forState:UIControlStateNormal];
    
    if (![XMUtil isBlankString:model.voice_intro.file_url] &&  model.voice_intro.voice_length > 0) {
        self.vipLeadSpace.constant = 65;
        self.voiceBtn.hidden = NO;
        [self.voiceBtn setTitle:kStringFormat(@"%ld″", model.voice_intro.voice_length) forState:UIControlStateNormal];
    } else {
        self.vipLeadSpace.constant = 8;
        self.voiceBtn.hidden = YES;
    }
    
    self.onlineView.hidden = model.is_online.intValue != 1;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    kCornerRadius(_userHeadImgV, 10, 0, UIColor.clearColor);
    kCornerRadius(_chatButton, 25, 0, UIColor.clearColor);
    [_userAgeSexBtn setImagePosition:(XMImagePositionLeft) spacing:3];
    [_chatButton setImagePosition:(XMImagePositionTop) spacing:0];

}

- (IBAction)chat:(UIButton *)sender {
    if (self.chatBlock) {
        self.chatBlock();
    }
}


@end
